/**
 * Copyright: Copyright (c) 2018
 * Company:
 *
 * @author XueWei
 * @date 2018年8月30日 下午1:11:00
 * @version V1.0
 */
package com.smartcommunity.controller.businessCircle;

import com.smartcommunity.bean.model.Pager;
import com.smartcommunity.bean.model.Result;
import com.smartcommunity.controller.BaseController;
import com.smartcommunity.entity.village.RealCompany;
import com.smartcommunity.entity.village.RealCompanyPeople;
import com.smartcommunity.entity.village.dto.UpdateRealCompanyPeopleDto;
import com.smartcommunity.log.interceptor.Log;
import com.smartcommunity.service.businessCircle.RealCompanyService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.HashMap;
import java.util.Map;

/**
 * @author XueWei
 * @ClassName: RealCompanyController
 * @Description: 实有单位controller类
 * @date 2018年8月30日 下午1:11:00
 */
@RestController
@RequestMapping(value = "/realCompany")
@Api(value = "小区服务-实有单位", tags = "实有单位")
@Slf4j
public class RealCompanyController extends BaseController {

    @Autowired
    private RealCompanyService realCompanyService;

    /**
     * 获取实有单位分页列表
     *
     * @param villageCode 小区ID
     * @param text 搜索关键字，支持根据单位名称、单位地址搜索
     * @param pageNumber  当前页
     * @param pageSize    每一页展示的条数
     * @return
     */
    @GetMapping(value = "/pageRealCompanies")
    @ApiOperation(value = "获取实有单位分页列表", notes = "获取实有单位分页列表")
    @Log(info = "查询实有单位列表信息",module = "实有单位",function = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "villageCode", value = "小区编号"),
            @ApiImplicitParam(name = "text", value = "关键字检索(支持单位名称、单位地址)"),
            @ApiImplicitParam(name = "parentId" ,value = "行政区划ID"),
            @ApiImplicitParam(name = "pageNumber" ,value = "页码",example = "1"),
            @ApiImplicitParam(name = "pageSize" ,value = "页数",example = "10")
    })
    public Result pageRealCompanies(
            @RequestParam(required = false, name = "villageCode") String villageCode,
            @RequestParam(required = false, name = "text") String text,
            @RequestParam(required = false, name = "pageNumber") String pageNumber,
            @RequestParam(required = false, name = "pageSize") String pageSize,
            @RequestParam(required = false, name = "parentId") String parentId) {
        log.info("接口：pageRealCompanies；获取实有单位分页列表");
        Map<String, Object> map = new HashMap<>(2);
        map.put("text", text);
        map.put("villageCode", villageCode);
        Pager<RealCompany> page = realCompanyService.pageRealCompanies(map, getPageNumber(pageNumber), getPageSize(pageSize));
        return Result.ok(page);
    }

    /**
     * 获取从业人员分页列表
     * @param companyId   单位id
     * @param pageNumber  当前页
     * @param pageSize    每一页展示的条数
     * @return
     */
    @GetMapping(value = "/pageRealCompanyPeoples")
    @ApiOperation(value = "获取从业人员分页列表", notes = "获取从业人员分页列表")
    @Log(info = "查询从业人员分页列表",module = "实有单位",function = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司id"),
            @ApiImplicitParam(name = "text", value = "关键字（姓名，证件号码，电话号码）")
    })
    public Pager<RealCompanyPeople> pageRealCompanyPeoples(
            @RequestParam(required = false, name = "companyId") String companyId,
            @RequestParam(required = false, name = "text") String text,
            @RequestParam(required = false, name = "pageNumber") String pageNumber,
            @RequestParam(required = false, name = "pageSize") String pageSize) {
        log.info("接口：pageRealCompanyPeoples；获取从业人员分页列表");
        Map<String, Object> map = new HashMap<>(10);
        map.put("companyId", companyId);
        map.put("text", text);
        return realCompanyService.pageRealCompanyPeoples(map, getPageNumber(pageNumber), getPageSize(pageSize));

    }

    @GetMapping(value = "/getRealCompany")
    @ApiOperation(value = "获取实有单位信息", notes = "获取实有单位信息")
    @Log(info = "查询实有单位具体信息",module = "实有单位",function = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "实有单位id")
    })
    public Result getRealCompany(@RequestParam(required = true, name = "companyId") String companyId) {
        log.info("接口：getRealCompany；获取实有单位信息");
        return realCompanyService.getRealCompany(companyId);

    }


    /**
     * @param realCompany
     * @return Result
     * @Title: addRealCompany
     * @Description: 新增实有单位
     */
    @PostMapping(value = "/insertRealCompany")
    @ApiOperation(value = "新增实有单位数据", notes = "新增实有单位数据")
    @Log(info = "新增实有单位信息",module = "实有单位",function = "新增")
    public Result insertRealCompany(@Valid @RequestBody @ApiParam(name = "realCompany", value = "单位对象")  RealCompany realCompany) {
        log.info("接口：insertRealCompany；新增实有单位数据。");
        return realCompanyService.insertRealCompany(realCompany);
    }

    /**
     * @param realCompany
     * @return Result
     * @Title: updateRealCompany
     * @Description: 修改实有单位
     */
    @PostMapping(value = "/updateRealCompany")
    @ApiOperation(value = "修改实有单位", notes = "修改实有单位")
    @Log(info = "修改实有单位信息",module = "实有单位",function = "修改")
    public Result updateRealCompany(@Valid @RequestBody @ApiParam(name = "realCompany", value = "单位对象")  RealCompany realCompany) {
        log.info("接口：updateRealCompany；更新实有单位信息。");
        return realCompanyService.updateRealCompany(realCompany);
    }

    /**
     * @param companyId
     * @return
     * @Title: deleteRealCompany
     * @Description: 删除实有单位
     */
    @DeleteMapping(value = "/deleteRealCompany")
    @Log(info = "删除实有单位信息",module = "实有单位",function = "删除")
    @ApiOperation(value = "删除实有单位", notes = "删除实有单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司ID")
    })
    public Result deleteRealCompany(@RequestParam(name = "companyId") String companyId) {
        log.info("接口：deleteRealCompany；删除实有单位。");
        return realCompanyService.deleteRealCompany(companyId);
    }

    /**
     * @Author: watermelon
     * @Description: 修改单位的经纬度
     * @Param: [companyId, villageCode, lon, lat]
     * @return: void
     * @Date: 2018/10/10 0010 9:59
     */
    @PostMapping(value = "/updateCompanyCoordinate")
    @ApiOperation(value = "修改实有单位的经纬度", notes = "修改实有单位的经纬度")
    @Log(info = "修改实有单位的经纬度",module = "实有单位",function = "修改")
    public Result updateCompanyCoordinate(@RequestBody @ApiParam(name = "realCompany", value = "单位对象")  RealCompany realCompany) {
        log.info("接口：updateCompanyCoordinate；修改单位的经纬度。");
        realCompanyService.updateCompanyCoord(realCompany);
        return Result.ok();
    }


    /**
     * @param realCompanyPeople
     * @return
     * @Title: addRealCompanyPeople
     * @Description: 新增从业人员
     */
    @PostMapping(value = "/insertRealCompanyPeople")
    @ApiOperation(value = "新增从业人员", notes = "新增从业人员")
    @Log(info = "新增实有单位从业人员信息",module = "实有单位",function = "新增")
    public Result insertRealCompanyPeople(@Valid @RequestBody @ApiParam(name = "realCompanyPeople", value = "单位从业人员对象") RealCompanyPeople realCompanyPeople) {
        log.info("接口：insertRealCompanyPeople；新增实有单位从业人员信息。");
        return realCompanyService.insertRealCompanyPeople(realCompanyPeople);
    }

    /**
     * @param realCompanyPeople
     * @return
     * @Title: updateRealCompanyPeople
     * @Description: 更新从业人员
     */
    @PostMapping(value = "/updateRealCompanyPeople")
    @ApiOperation(value = "更新从业人员", notes = "更新从业人员")
    @Log(info = "更新实有单位从业人员信息",module = "实有单位",function = "更新")
    public Result updateRealCompanyPeople(@Valid @RequestBody @ApiParam(name = "realCompanyPeople", value = "单位从业人员对象") UpdateRealCompanyPeopleDto realCompanyPeople) {
        log.info("接口：updateRealCompanyPeople；更新从业人员。");
        return realCompanyService.updateRealCompanyPeopleNew(realCompanyPeople);
    }

    /**
     * @param id
     * @return
     * @Title: deleteRealCompanyPeople
     * @Description: 删除实有单位从业人员信息
     */
    @DeleteMapping(value = "/deleteRealCompanyPeople")
    @ApiOperation(value = "删除实有单位从业人员信息", notes = "删除实有单位从业人员信息")
    @Log(info = "删除实有单位从业人员信息",module = "实有单位",function = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "从业人员id，多个用逗号分隔")
    })
    public Result deleteRealCompanyPeople(@RequestParam(name = "id") String id) {
        log.info("接口：deleteRealCompanyPeople；删除实有单位从业人员信息。");
        return realCompanyService.deleteRealCompanyPeople(id);
    }

    @GetMapping(value = "/getRealCompanyPeople")
    @Log(info = "查询实有单位从业人员信息",module = "实有单位",function = "查询")
    @ApiOperation(value = "获取实有单位从业人员信息", notes = "获取实有单位从业人员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "从业人员id")
    })
    public Result getRealCompanyPeople(@RequestParam(required = true, name = "id") String id) {
        log.info("接口：getRealCompany；获取实有单位信息");
        return realCompanyService.getRealCompanyPeople(id);
    }


    /**
     * @param map
     * @return
     * @Title: deleteRealCompanyPeople
     * @Description: 查询实有单位数量
     */
    @PostMapping(value = "/countRealCompanies")
    @Log(info = "查询实有单位数量",module = "实有单位",function = "查询")
    @ApiOperation(value = "查询实有单位数量", notes = "查询实有单位数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map", value = "map")
    })
    public int countRealCompanies(@RequestParam Map<String, Object> map) {
        log.info("接口：countRealCompanies；查询实有单位数量。");
        int i;
        i = realCompanyService.countRealCompanies(map);
        return i;
    }
}
